import {myRequest} from './http.js'
import {getToken, getTokenId} from "@/common/auth";

//获取所有商家
export function getAllBusinessApi() {
    return myRequest({
        url: '/business/getAll',
        method: 'get'
    })
}

// 根据店家ID查询该店家的菜品
export function getDishApi(businessId) {
    return myRequest({
        url: '/dish/getDish/' + businessId,
        method: 'GET',
    })
}


//根据id获取店家信息
export function getInfoApi(businessId) {
    return myRequest({
        url: '/business/getInfo/' + businessId,
        method: 'GET',
    })
}


// 根据用户ID查询用户订单
export function getOrderApi() {
    return myRequest({
        url: '/order/userGet/' + getTokenId(),
        method: 'GET',
    })
}


// 根据id获取用户信息
export function getUserInfoApi() {
    return myRequest({
        url: '/user/getInfo/' + getTokenId(),
        method: 'GET',
    })
}

// 用户登录
export function loginApi(data) {
    return myRequest({
        url: '/user/login',
        method: 'POST',
        data
    })
}


// logout
export function logoutApi() {
    return myRequest({
        url: '/user/logout',
        method: 'POST',
    })
}

// 用户注册
export function registerApi(data) {
    return myRequest({
        url: '/user/register',
        method: 'POST',
        data
    })
}

// 修改个人信息
export function updateApi() {
    return myRequest({
        url: '/user/update',
        method: 'POST',
    })
}


//POST
// /employee/register
// 外卖员注册
//外卖员注册
export function registerEmApi(data) {
    return myRequest({
        url: '/employee/register',
        method: 'POST',
        data
    })
}

//POST
// /employee/login
// 外卖员登录
export function loginEmApi(data) {
    return myRequest({
        url: '/employee/login',
        method: 'POST',
        data
    })
}


//GET
// /cabinet/all
// 查看所有外卖柜
export function getAllCabinetApi() {
    return myRequest({
        url: '/cabinet/all',
        method: 'GET'
    })
}


/*
* 购物车管理
* */

//新增购物车菜品
export function addCartApi(data) {
    return myRequest({
        url: '/cart/add',
        method: 'POST',
        data
    })
}


//删除购物车菜品
export function delCartApi(data) {
    return myRequest({
        url: '/cart/del/',
        method: 'DELETE',
        data
    })
}


//获取当前用户购物车菜品
export function getCartApi() {
    return myRequest({
        url: '/cart/get/' + getTokenId(),
        method: 'GET'
    })
}


//清空购物车菜品
export function removeAllCarApi() {
    return myRequest({
        url: '/cart/removeall/' + getTokenId(),
        method: 'DELETE'
    })
}

/*用户地址管理
Address Controller*/

//添加地址
export function addAddressApi(data) {
    return myRequest({
        url: '/address/add',
        method: 'POST',
        data
    })
}


//根据id删除地址
export function deleteAddressApi(id) {
    return myRequest({
        url: '/address/delete/' + id,
        method: 'DELETE'
    })
}

//根据用户id获取地址
export function getUserAddressApi() {
    return myRequest({
        url: '/address/getInfo/' + getTokenId(),
        method: 'GET'
    })
}

//修改地址
export function updateAddressApi(data) {
    return myRequest({
        url: '/address/update',
        method: 'PUT',
        data
    })
}


/*
* 订单管理
Order Controller
* */


// 用户提交订单
export function addOrderApi(data) {
    return myRequest({
        url: '/order/add',
        method: 'POST',
        data
    })
}


//根据店家ID查询所有订单

export function getAllOrderByBusApi(id) {
    return myRequest({
        url: '/order/businessGet/' + id,
        method: 'GET'
    })
}


//根据订单ID查询订单
export function getByIdApi(id) {
    return myRequest({
        url: '/order/getById/' + id,
        method: 'GET'
    })
}




//查询未接单的订单
export function getUnExcpetApi() {
    return myRequest({
        url: '/order/getUnExcpet' ,
        method: 'GET'
    })
}

//订单状态 1待付款，2待派送，3已接单，4已派送，5已完成，6已取消

export function updateStautsApi(data) {
    return myRequest({
        url: '/order/updateStauts',
        method: 'PUT',
        data
    })
}


//PUT
//           /cabinet/update
//           修改快递柜状态 外卖柜位置、状态

export function updateCarApi(data) {
    return myRequest({
        url: '/cabinet/update',
        method: 'PUT',
        data
    })
}


//根据外卖员ID查询订单

export function getByEmployeeIdApi() {
    return myRequest({
        url: '/order/getByEmployeeId/'+getTokenId(),
        method: 'GET'
    })
}